package cruds.accessories.brand;

import java.util.List;

import items.BrandDTO;
import items.Stockable;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.navigation.paging.PagingNavigator;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.markup.repeater.data.IDataProvider;
import org.apache.wicket.model.AbstractReadOnlyModel;

import cruds.ParentList;
import dataproviders.BrandDataProvider;
import dynamicmenus.BrandModelMenu;
import home.Home;


@SuppressWarnings("serial")
public class BrandsList extends ParentList<BrandDTO>{
	
	private String type;
	
	public BrandsList(Home home,String type, List<BrandDTO> items) {
		super(home,items);
		this.type = type;
	}

	@Override
	protected void updateDynamicMenu(AjaxRequestTarget target) {
		BrandModelMenu menu = new BrandModelMenu(this.getHome());
		menu.changePanel(target);
	}

	@Override
	protected void doUpdateAndRedirect(AjaxRequestTarget target,Item<BrandDTO> item) {
		CrudModifyBrand panel = new CrudModifyBrand(this.getHome(),item.getModelObject());
		panel.changePanel(target);
	}

	@Override
	protected void doDeleteAndRedirect(AjaxRequestTarget target,Item<BrandDTO> item) {
		this.getService().delete(item.getModelObject());
		BrandsList list = new BrandsList(this.getHome(),this.type,this.getHome().getGeneralService().getBrandSer().getBrandsAndModels(this.type));
		list.changePanel(target);
	}

	@Override
	protected void createFormFields(Item<BrandDTO> item) {
		item.add(new Label("brand",item.getModelObject().getBrand()));
		item.add(new Label("model",item.getModelObject().getModel()));	
	}

	@Override
	protected void initializeService() {
		this.setService(this.getHome().getGeneralService().getBrandSer());
		
	}

	@Override
	protected IDataProvider setDataProvider() {
		return new BrandDataProvider(this.getItems());
	}

	@Override
	protected void initializePanelTH(Form form) {
		form.add(new BrandsListTH());
		
	}


}
